<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page import="com.yy.base.util.UserUtil"%>
<%@page import="com.mes.entity.User"%>
<%
User user = (User)session.getAttribute(UserUtil.USERSESSION);
if (user == null) {
	response.sendRedirect(request.getContextPath());
	return;
}
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="format-detection" content="telephone=no"/>
	<link href="script/css/iconfont.css" rel="stylesheet" type="text/css"></link>
	<script src="script/mes-import.js"></script>

	<script type="text/javascript">
	top.$("#page_title_panel").hide();
    top.$("#page_header").show();
    top.$("#main_page_title").html("&nbsp;");

	var clientIp = window.location.host;
	if(location.href.indexOf("192.168.32") > -1){
		clientIp = "192.168.32.13:18080";
	}
	$(function() {
		$.post(host + 'loginController/getMenus.html', {}, function(result) {
			var data = result.data;
			var nodes = [];
			var map = {};
			var menuMap = {};
			for (var i = 0;i < data.length;i ++) {
				if (data[i].parentId && data[i].parentId != "0") {
					if (!menuMap[data[i].parentId]) {
						menuMap[data[i].parentId] = [];
					}
					menuMap[data[i].parentId].push(data[i]);
				}
			}
			for (var i = 0;i < data.length;i ++) {
				map[data[i].id] = data[i];
				if (!menuMap[data[i].parentId]) {
					if (menuMap[data[i].id]) {
						map[data[i].id].children = menuMap[data[i].id];
					}
					nodes.push(map[data[i].id]);
				}
			}

			var reg = /(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\:(\d{1,})/;
			for (var i = 0;i < nodes.length;i ++) {
			    var panel = $('<div class="grid_menu"></div>');
                $("#scrollContent").append(panel);
                panel.append('<div class="title">' + nodes[i].name + '</div>');
				if(nodes[i].children) {
					var children = nodes[i].children;
					for(var j = 0;j < children.length; j++) {
                        var div = $('<div class="item"></div>');
                        panel.append(div);
						//根据IP识别报表平台地址
						url = children[j].url ? children[j].url.replace(reg, clientIp) : '';
						
						div.append('<a href="javascript: void(0);" onclick="openMenu(\''+ url +'\',\''+children[j].icon+'\',\''+children[j].name+'\');return false;">' +
							'<i class="iconfont icon-touzi ' + children[j].icon + '"></i>' +
							'<h3 class="navIcon_right_title">'+ children[j].name +'</h3></a>');
					}
				}
			}
            setMenuItemWidth();
		}, "json");
	});
	function setMenuItemWidth() {
        var width = document.body.clientWidth - 30;
        var w = width / 150;
        var itemWidth = width / Math.floor(w);
        if (itemWidth > 160) {
            itemWidth = width / (Math.floor(w) + 1);
        }
        $(".item").each(function(i) {
            $(this).css("width", itemWidth + "px");
		});
	}
	function openMenu(url, icon, name) {
        var width = document.body.clientWidth;
        if (width < 750) {
            top.$("#page_header").hide();
            top.$("#page_title_panel").show();
            top.$("#page_title", window.parent.document).html(name);
        }
		var connector = "?";
		if(url.indexOf('?') > 0 ) {
            connector = "&";
		}
        top.$("#main_page_title").html(name);
		window.location.href = url+connector+"random="+Math.random();
	}
    var changing = false;
    window.onresize = function() {
        if (changing) {
            return;
        }
        changing = true;
        window.setTimeout(function() {
            changing = false;
            setMenuItemWidth();
        }, 200);
    }
	</script>
</head>
<body>
	<div id="scrollContent" style="padding-bottom: 10px;">

	</div>
	<div class="foohi" id="foot_menu" style="display: none;">
		<div class="footer">
			<ul>
				<li style="float:left;">
					<a class="yello" href="javascription: void(0);">
						<div class="icon"><i class="icon-gongneng iconfont"></i>
							<p>操作</p>
						</div>
					</a>
				</li>
				<li>
					<a href="javascription: void(0);">
						<div class="icon"><i class="icon-my iconfont"></i>
							<p>我的信息</p>
						</div>
					</a>
				</li>
				<li>
					<a href="javascription: void(0);">
						<div class="icon"><i class="icon-yinxingqia iconfont"></i>
							<p>退出</p>
						</div>
					</a>
				</li>
			</ul>
		</div>
	</div>
</body>
</html>